<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="70%" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false">
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right" style="height:550px;overflow:auto">
            <el-row :gutter="1">
                <el-col :span="12">
                    <el-form-item label="巡检任务编码" prop="code">
                        <el-input v-model="code" clearable placeholder="巡检任务编码"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="巡检设备名称" prop="title">
                        <el-input v-model="title" clearable placeholder="巡检设备名称"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="巡检详情 " prop="item">
                <sc-form-table ref="table" v-model="form.item" :addTemplate="addTemplate" placeholder="暂无数据" hideAdd hideDelete>
                    <el-table-column prop="title" label="巡检项目" align="center"></el-table-column>
                    <el-table-column prop="con" label="巡检内容" align="center"></el-table-column>
                    <el-table-column prop="type" label="方法" align="center">
                            <template #default="scope">
                                <el-select v-model="scope.row.type" placeholder="请选择" disabled>
                                    <el-option label="目视" :value="1"></el-option>
                                    <el-option label="触摸" :value="2"></el-option>
                                    <el-option label="耳听" :value="3"></el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                    <el-table-column prop="ask" label="要求" align="center"></el-table-column>
                    <el-table-column prop="sta" label="是否正常" align="center">
                        <template #default="{row}">
                            <el-radio-group v-model="row.sta" class="ml-4">
                                <el-radio :label="0" size="large">OK</el-radio>
                                <el-radio :label="1" size="large">NG</el-radio>
                            </el-radio-group>
                        </template>
                    </el-table-column>
                </sc-form-table>
            </el-form-item>
            <el-form-item label="巡检设备照片" prop="img">
                <sc-upload-multiple v-model="form.img" draggable disabled></sc-upload-multiple>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" clearable placeholder="请输入备注"></el-input>
            </el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增保养记录',
				edit: '巡检',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				task_id: "",
				yes: "",
				no: "",
				item: [],
                img:"",
                remark:"",
			},
            code:"",
            title:"",
            addTemplate:{ item_id:"",value:"",type:"",},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单注入数据
		async setData(data) {
            console.log(123);
            var res = await this.$API.device.InspectionProjectLog.detail.post({id:data.id})
            this.code = res.data.task_code
            this.title = res.data.device_title
            this.form.remark = res.data.remark
            res.data.item.map(item=>{
                item.sta = Number(item.sta)
            })
            this.form.item = res.data.item
            this.form.img = res.data.img
		},
	}
}
</script>

<style></style>
